package cn.bgs.service.Impl;

import cn.bgs.mapper.CellMapper;
import cn.bgs.mapper.InfoMapper;
import cn.bgs.pojo.Building;
import cn.bgs.pojo.CommunityVo;
import cn.bgs.pojo.Portal;
import cn.bgs.service.InfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InfoServiceImpl implements InfoService {
    @Autowired
    private InfoMapper infoMapper;
    @Autowired
    private CellMapper cellMapper;
    @Override
    public PageInfo<CommunityVo> page1(String communityId,String houseuse, String howmany, Integer pagesize, Integer pagenow) {
        if(pagenow==null){
            pagenow=1;
        }
        if(pagesize==null){
            pagesize=10;
        }
        PageHelper.startPage(pagenow,pagesize);
        List<CommunityVo> communityVoList = infoMapper.findinfo(communityId,houseuse,howmany);
        PageInfo<CommunityVo> c = new PageInfo<>(communityVoList);
        return c;
    }

    @Override
    public PageInfo<CommunityVo> page2(String communityId,String houseuse, String state, Integer pagesize, Integer pagenow) {
        if(pagenow==null){
            pagenow=1;
        }
        if(pagesize==null){
            pagesize=10;
        }
        PageHelper.startPage(pagenow,pagesize);
        List<CommunityVo> communityVoList = infoMapper.findhouse(communityId,houseuse,state);
        PageInfo<CommunityVo> a = new PageInfo<>(communityVoList);
        return a;
    }

    @Override
    public void addCommunity(Building forms) {
         infoMapper.addCommunity(forms);
         Integer buildingId=forms.getBuildingId();
         String communityId=forms.getCommunityId();
         cellMapper.add(communityId,buildingId);
    }

    @Override
    public void del(Integer id) {
        infoMapper.del(id);
    }

    @Override
    public void updatebuilding(Building formData) {
        infoMapper.updatebuilding(formData);
    }

    @Override
    public List<Building> load(Integer id) {
        List<Building> building = infoMapper.load(id);
        return building;
    }

    @Override
    public void addportal(Portal forms) {
        infoMapper.addportal(forms);
        String communityId = forms.getCommunityId();
        Integer portalId=forms.getPortalId();
        String buildingId=forms.getBuildingId();
        cellMapper.adds(communityId,buildingId,portalId);
    }

    @Override
    public void delportal(Integer id) {
        infoMapper.delportal(id);
    }
}